<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>圖片上傳</title>

<script type="text/javascript" src="/ad/html/js/util.js"></script>
<link rel="stylesheet" type="text/css" href="/ad/html/js/ext/file-upload.css"/>
<script type="text/javascript" src="/ad/html/js/ext/FileUploadField.js"></script>
 
 <script type="text/javascript">
 		/*
		Ext.require([
			'Ext.form.field.File',
			'Ext.form.Panel'
		]);*/
 		
 		window.onload = function(){
 			
 			var  fp = new Ext.FormPanel({
 				fileUpload: true,
   		        renderTo: 'form',
 		        height      : 109,
                width       :  520,
 		        frame: true,
 		        title: 'File Upload Form',
 		        //buttonAlign : "center",
  		        labelWidth: 50,
  		        bodyStyle: 'padding: 10px 10px 0 10px;',
    		      defaults: {
    	  	            anchor: '98%',
    	  	            msgTarget: 'side'
    	  	        },

 		        items: [{
 		           
 		            id: 'form-file',
 		            name : 'Filedata',
 		            regex:/.jpg|.JPG|.BMP|.bmp|.png|.PNG|.gif|.GIF/,  
                    regexText:"上傳檔案非圖片檔案",
                    emptyText: '請選擇上傳圖片....', 
 		            fieldLabel: 'Photo',
  		            xtype: 'fileuploadfield',
		            id: 'form-file',
		            buttonText: '',
		             
		            buttonCfg: {
		                iconCls: 'upload-icon'
		            }
 		             
 		        }],
 		       buttons: [
                   {
                     text: '上傳',
                     handler: function(){
                      	var form = fp.getForm();
                    	var file = form.findField("Filedata");
                        if (file.getValue() == "") {
                        	alert("請選擇圖片檔案!");
                        	return;
                        } 
                         
                        if (!/.jpg|.JPG|.BMP|.bmp|.png|.PNG|.gif|.GIF/.test(file.getValue())) {
                            alert ('上傳檔案非圖片檔案!');
                            return;
                        }
                         
                        var mask = createMask("圖片新增中...");
                        mask.show();
                            form.submit({
                                url: '/ad/upload/uploadImg.php?floder=<?php echo $_GET["floder"]?>',
                                //waitMsg: '圖片新增中...',
                                success: function(fp, o){
                                    mask.hide();
                                    alert (o.result.msg);
                                    window.close();
                                    window.returnValue = o.result.url;
                                    
                                },
                                failure : function (fp, o) {
                                	mask.hide();
                                	alert ("error:"+o.result.msg); 
                                } 
                            });
                         
                     }
                   },
                   {
                     text : "關閉",
                     handler : function () {
                        window.close();
                     }
                   }
                ]
 		    })
 	}
</script>
</head>
<body scroll=no >
	 
		<div id="form"></div>
	 
</body>
</html>